using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace QuanLyKhachHang.DAO
{
	#region using
	using System.Data;
	using QuanLyKhachHang.DTO;
	#endregion
	public class DonViDAO : AbstractDAO
	{
		public DonViDAO(String strPath): base(strPath)
		{
		}

		~DonViDAO()
		{
			base.Dispose();
		}

		public DataSet SelectAll()
		{
			DataSet ds;
			try
			{
				ds = new DataSet();
				base.sql = "usp_DonVi_SelectAll";
				base.FillDataSet(ref ds, "DonVi");
				return ds;
			}
			catch(System.Exception e)
			{
				throw new Exception(e.Message, e.InnerException);
			}
			finally
			{
				base.CleanUpObject();
			}
		}

		public DataSet SelectByID(string madonvi)
		{
			DataSet ds;
			try
			{
				ds = new DataSet();
				base.sql = "usp_DonVi_SelectByID";
				base.InitializeCommand();
				base.AddParameter("@MADONVI", SqlDbType.NVarChar, 100, madonvi);
				base.FillDataSet(ref ds, "DonVi");
				return ds;
			}
			catch(System.Exception e)
			{
				throw new Exception(e.Message, e.InnerException);
			}
			finally
			{
				base.CleanUpObject();
			}
		}

		public bool Insert(DonViDTO obj)
		{
			try
			{
				base.sql = "usp_DonVi_Insert";
				base.InitializeCommand();
				base.AddParameter("@MADONVI", SqlDbType.NVarChar, 100, obj.MADONVI);
				base.AddParameter("@TENDONVI", SqlDbType.NVarChar, 100, obj.TENDONVI);
				return ExecuteStoredProcedure();
			}
			catch
			{
				return false;
			}
		}

		public bool Delete(string madonvi)
		{
			try
			{
				base.sql = "usp_DonVi_Delete";
				base.InitializeCommand();
				base.AddParameter("@MADONVI", SqlDbType.NVarChar, 100, madonvi);
				return ExecuteStoredProcedure();
			}
			catch
			{
				return false;
			}
		}

		public bool Update(DonViDTO obj)
		{
			try
			{
				base.sql = "usp_DonVi_Update";
				base.InitializeCommand();
				base.AddParameter("@MADONVI", SqlDbType.NVarChar, 100, obj.MADONVI);
				base.AddParameter("@TENDONVI", SqlDbType.NVarChar, 100, obj.TENDONVI);
				return ExecuteStoredProcedure();
			}
			catch
			{
				return false;
			}
		}

	}
}